import Vue from 'vue'
import VueRouter from 'vue-router'
// import Login from '../components/Login.vue'
const Login = () => import(/* webpackChunkName: "login_home_welcome" */ '../components/Login.vue')
// import Home from '../components/Home.vue'
const Home = () => import(/* webpackChunkName: "login_home_welcome" */ '../components/Home.vue')
// import Welcome from '../components/Welcome'
const Welcome = () => import(/* webpackChunkName: "login_home_welcome" */ '../components/Welcome')

// import Users from '../components/user/Users'
const Users = () => import(/* webpackChunkName: "users_rights_roles" */ '../components/user/Users')
// import Rights from '../components/power/Rights'
const Rights = () => import(/* webpackChunkName: "users_rights_roles" */ '../components/power/Rights')
// import Roles from '../components/power/Roles'
const Roles = () => import(/* webpackChunkName: "users_rights_roles" */ '../components/power/Roles')

// import Cate from "../components/goods/Cate"
const Cate = () => import(/* webpackChunkName: "cate_params_list_addgoods" */ '../components/goods/Cate')
// import Params from "../components/goods/Params"
const Params = () => import(/* webpackChunkName: "cate_params_list_addgoods" */ '../components/goods/Params')
// import List from "../components/goods/List"
const List = () => import(/* webpackChunkName: "cate_params_list_addgoods" */ '../components/goods/List')
// import addGoods from "../components/goods/addGoods"
const addGoods = () => import(/* webpackChunkName: "cate_params_list_addgoods" */ '../components/goods/addGoods')

// import Order from "../components/orders/Order"
const Order = () => import(/* webpackChunkName: "order" */ '../components/orders/Order')

// import Reports from "../components/report/Reports"
const Reports = () => import(/* webpackChunkName: "reports" */ '../components/report/Reports')

Vue.use(VueRouter)

const routes = [
  {
    path:'/',redirect:'/login'
  },
  {
    path:'/login',
    component:Login
  },
  {
    path:'/home',
    component:Home,
    redirect:'/welcome',
    children:[
      {path:'/welcome',component:Welcome},
      {path:'/users',component:Users},
      {path:'/rights',component:Rights},
      {path:'/roles',component:Roles},
      {path:'/categories',component:Cate},
      {path:'/params',component:Params},
      {path:'/goods',component:List},
      {path:'/addgoods',component:addGoods},
      {path:'/orders',component:Order},
      {path:'/reports',component:Reports}
    ]
  }
]

const router = new VueRouter({
  routes,
  mode:'history'
})
router.beforeEach((to,from,next)=>{
  if(to.path==='/login') return next()
  const loginSession=window.sessionStorage.getItem('token')
  if(!loginSession){
    return next('/login')
  }
  else{
    next()
  }
})
export default router
